﻿using PracticeCentre.Common;
using PracticeCentre.DataControl;
using PracticeCentre.Modeles;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PracticeCentre.Business
{
    /// <summary>
    /// 招聘管理
    /// </summary>
    public class Recruitment
    {

	/// <summary>
        /// 分页获取人员信息列表
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageModel<RecruitmentState> GetPlanList(PageModel<RecruitmentState> page)
        {
             DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                SqlParameter[] vs = new SqlParameter[] {
                     new SqlParameter("@sys_PageIndex",page.PageNumber),
                    new SqlParameter("@sys_PageSize",page.PageSize),
                    new SqlParameter("@sys_Table","RecruitmentState"),
                    new SqlParameter("@sys_Key","ID"),
                    new SqlParameter("@sys_Where",""),
                    new SqlParameter("@sys_Order","ID"),
                    new SqlParameter("@sys_AscOrDesc",""),
                    new SqlParameter("@pageCount",page.PageCount),
                    new SqlParameter("@recordCount",page.RowCount)
                };
                vs[7].Direction = ParameterDirection.Output;
                vs[8].Direction = ParameterDirection.Output;
                int pagecount = 0;
                int rowcount = 0;
                DataTable dt = dataHelper.ExecuteDataTable<RecruitmentState>(ProceduresConfig.GeneralPaging, out pagecount, out rowcount, vs);
                DataModelHandler<RecruitmentState> dataHandler = new DataModelHandler<RecruitmentState>();
                List<RecruitmentState> postList = dataHandler.FillModel(dt);
                page.PageCount = pagecount;
                page.RowCount = rowcount;
                page.DataList = postList;
                return page;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
	
        /// <summary>
        /// 分页获取人员信息列表
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageModel<RecruitmentPlan> GetPlanList(PageModel<RecruitmentPlan> page)
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@sys_PageIndex",page.PageNumber),
                    new SqlParameter("@sys_PageSize",page.PageSize),
                    new SqlParameter("@sys_Table","RecruitmentPlan"),
                    new SqlParameter("@sys_Key","id"),
                    new SqlParameter("@sys_Where",""),
                    new SqlParameter("@sys_Order","id"),
                    new SqlParameter("@sys_AscOrDesc",""),
                    new SqlParameter("@pageCount",page.PageCount),
                    new SqlParameter("@recordCount",page.RowCount)
                };
                parameters[7].Direction = ParameterDirection.Output;
                parameters[8].Direction = ParameterDirection.Output;
                int pagecount = 0;
                int rowcount = 0;
                DataTable dt = dataHelper.ExecuteDataTable<Personal>(ProceduresConfig.GeneralPaging, out pagecount, out rowcount, parameters);
                DataModelHandler<RecruitmentPlan> dataHandler = new DataModelHandler<RecruitmentPlan>();
                List<RecruitmentPlan> postList = dataHandler.FillModel(dt);
                page.PageCount = pagecount;
                page.RowCount = rowcount;
                page.DataList = postList;
                return page;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

		/// <summary>
        /// 分页获取招聘需求信息列表
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageModel<View_Recruitment> GetPlanList(PageModel<View_Recruitment> page)
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@sys_PageIndex",page.PageNumber),
                    new SqlParameter("@sys_PageSize",page.PageSize),
                    new SqlParameter("@sys_Table","View_Recruitment"),
                    new SqlParameter("@sys_Key","ReitID"),
                    new SqlParameter("@sys_Where"," ReitState=2"),
                    new SqlParameter("@sys_Order","ReitID"),
                    new SqlParameter("@sys_AscOrDesc",""),
                    new SqlParameter("@pageCount",page.PageCount),
                    new SqlParameter("@recordCount",page.RowCount)
                };
                parameters[7].Direction = ParameterDirection.Output;
                parameters[8].Direction = ParameterDirection.Output;
                int pagecount = 0;
                int rowcount = 0;
                DataTable dt = dataHelper.ExecuteDataTable<View_Recruitment>(ProceduresConfig.GeneralPaging, out pagecount, out rowcount, parameters);
                DataModelHandler<View_Recruitment> dataHandler = new DataModelHandler<View_Recruitment>();
                List<View_Recruitment> postList = dataHandler.FillModel(dt);
                page.PageCount = pagecount;
                page.RowCount = rowcount;
                page.DataList = postList;
                return page;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// 招聘计划审批
        /// </summary>
        /// <returns></returns>
        public bool UpdateApprove(CreatePlan page)
        {
            DataControlHelper dataHelper = new DataControlHelper();
            SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@UserID",page.UserID),
                    new SqlParameter("@ReitID",page.ReitID),
                    new SqlParameter("@Salary",page.Salary),
                    new SqlParameter("@ReitState",page.ReitState),
                    new SqlParameter("@ReitRemark",page.ReitRemark)

                };
            return dataHelper.ExecuteNoQuery("Proc_UpReit", parameters);
        }
		
        /// <summary>
        /// 制定招聘计划
        /// </summary>
        /// <returns></returns>
        public bool MakePlan(RecruitmentPlan model)
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@PositionId",model.PositionId),
                    new SqlParameter("@DepartmentId",model.DepartmentId),
                    new SqlParameter("@RecruitingCount",model.RecruitingCount),
                    new SqlParameter("@PostTime",model.PostTime),
                    new SqlParameter("@InterviewJobNumber",model.InterviewJobNumber),
                    new SqlParameter("@InterviewName",model.InterviewName),
                    new SqlParameter("@StartingTime",model.StartingTime)
                };
                return dataHelper.ExecuteNoQuery(ProceduresConfig.MakeAMonthlyRecruitmentPlan, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
         /// <summary>
        /// 岗位表信息查询
        /// </summary>
        /// <returns>
        /// 下拉框绑定数据
        /// </returns>
        public List<Position> GetAllPostList()
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {

                DataModelHandler<Position> modelHandler = new DataModelHandler<Position>();
                List<Position> personalList = modelHandler.FillModel(dataHelper.ExecuteDataTable(ProceduresConfig.GetAllPostList));
                return personalList.Count > 0 ? personalList : null;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        /// <summary>
        /// 部门表信息查询
        /// </summary>
        /// <returns>
        /// 下拉框绑定数据
        /// </returns>
        public List<Department> GetAllDeptList()
        {
            DataControlHelper dataHelper = new DataControlHelper();
            try
            {

                DataModelHandler<Department> modelHandler = new DataModelHandler<Department>();
                List<Department> departList = modelHandler.FillModel(dataHelper.ExecuteDataTable(ProceduresConfig.GetAllDepartmentList));
                return departList.Count > 0 ? departList : null;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public bool RecuriAdd(RecruitmentsAdd model)
        {

            DataControlHelper dataHelper = new DataControlHelper();
            try
            {
                SqlParameter[] parameters = new SqlParameter[] {
                   new SqlParameter("@PostID",model.PostID),
                   new SqlParameter("@ReitAmount",model.ReitAmount),
                   new SqlParameter("@ReportTime",model.ReportTime),
                   new SqlParameter("@Obligation",model.Obligation),
                   new SqlParameter("@Require",model.Require),
                   new SqlParameter("@CreateTime",model.CreateTime),
                   new SqlParameter("@DeptID",model.DeptID),
                    new SqlParameter("@UserID",model.UserID),
                     new SqlParameter("@ReitState",model.ReitState),
                      new SqlParameter("@ReitRemark",model.ReitRemark)


                };
                return dataHelper.ExecuteNoQuery(ProceduresConfig.RecruitmentNeedsRelease, parameters);


            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}
